var mm;
var myiscroll2;
var report_date;
var hei;
$(document).ready( function() {
	$(window).resize(function(){//当窗口大小改变时自动重新计算
		iscroll();
		myiscroll2.refresh();
	});
	/*
	var str = (location.search).substr(1);
	var param = str.split("&");
	var emplid = (param[0].split("="))[1];// 下属id
		report_date = (param[1].split("="))[1];
		mm = report_date.split("/")[1];// 月份
	var name = (param[2].split("="))[1];
		name = decodeURI(name,"utf-8");
	*/
	emplid = getQueryParam("emplid");
	report_date = getQueryParam("report_date");
	name = decodeURI(getQueryParam("name"),"utf-8");
	var mm = report_date.split("/")[1];
	var title = name + "的" + mm + "月汇报"
	$('#xsname').text(title);//显示标题
	$("#loadingText").show();
	$("#ContentIscrollHeight").hide();
	$("#FooterFixed").hide();
	$('#kList').html("");// 将kList中的内容清空
	$('#pList').html("");// 将pList中的内容清空
	iscroll();
	$.ajax( {
		type : "post",
		url : mpsurl+"/mobile/report/queryUnderlingReportInfo.do",
		dataType : "json",
		data : {
			method : "xslb-chakan",
			underlingEmplid : emplid,
			report_date : report_date
		},
		success : function(data) {
			$("#loadingText").hide();
			$("#ContentIscrollHeight").show();
			data = eval(data);
			if (data.resultCode == "500600") {
				$("#FooterFixed").show();
				showResult(data);
			} else {
				$("#content").hide();
				var tourl="/mobile/underlingReport/xslb-chakan2.html?underlingEmplid="
					+emplid+"&report_date="+report_date+"&name="+name;
				checkLogin(data.resultCode,tourl,data.resultMessage);
			}
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			$("#loadingText").hide();
			$("#content").hide();
			errorMask("网络连接异常");
		}
	});
	// 去查看评分页面
	$("#J-BtnSave").on("tap",function() {
		//location.href = "xslb-pingfen2.html?emplid=" + emplid + "&report_date=" + report_date+"&name="+name;
		var param = "emplid="+emplid+"&report_date="+report_date+"&name="+name;
		gotoLocation("/mobile/underlingReport/xslb-pingfen2.html",param);
	});
	//返回
	$("#back").on("tap",function(){
		//location.href="xslb.html?report_date="+report_date;
		var param = "report_date="+report_date;
		gotoLocation("/mobile/underlingReport/xslb.html",param);
	});
	//显示、关闭标题提示窗
	$(document).on("tap", function(e) {
		if($("#GlobalMask").css("display")!="none"){
			$("#GlobalMask").hide("slow");
		}
		if(e.target.id == "desc"){
			$("#GlobalMask").find("p").text($(e.target).text());
			$("#GlobalMask").show();
		}
		if(e.target.id=="Desc"){
			var parent = $(e.target).parents(".kpi-main");
			parent[parent.hasClass("open-kpi-cont") ? "removeClass" : "addClass"]
					("open-kpi-cont");
			myiscroll2.refresh();
		}
	});
});
//页面滚动
function iscroll() {
	var wh = $(window).height() - 90 - 112;
	if (myiscroll2 instanceof iScroll) {
		myiscroll2.destroy();
	}
	$("#content").css("height", wh + "px");
	myiscroll2 = new iScroll("content",{
			useTransition:false,
			checkDOMChanges: false,
	        bounce:false
	    });
}
//解析返回结果
function showResult(data) {
	var value = data.value;
	var kpi = eval(value.kpi);// kpi
	// 展示KPI
	if(kpi.length<1){
		$("#kList").parent().hide();
	}else{
		for ( var i = 0; i < kpi.length; i++) {
			var kl = $("<div class=\"kpi-main m-t18\">"
					+ "<h3 class=\"kpi-title icon-click\">"
					+ "<div class=\"row-left-icon\"><i>"+ (i + 1)+ "</i></div>"
					+ "<div class=\"info-list-cont\" id=\"desc\">"+ kpi[i].content_descr+ "</div>"
					+ "<div class=\"info-list-icon\" id=\"Desc\"></div>"
					+ "</h3>"
					+ "<div class=\"kpi-content row-info edit-row row-info-readonly\">"
					+ "<ul class=\"row-info-list\"><li>"
					+ "<div class=\"info-list-name\">预期目标：</div>"
					+ "<div class=\"info-list-cont\">"+ kpi[i].paic_cur_trgt+ "</div>"
					+ "</li>"
					+ "<li>"
					+ "<div class=\"info-list-name\">本月完成：</div>"
					+ "<div class=\"info-list-cont\">"+ kpi[i].paic_accmp_sta.replace(/\n/g,"<br>")+ "</div>" 
					+ "</li>" +
							"</ul></div>" +
							"</div>");
			$('#kList').append(kl);
		}
	}
	//解析ew不需评分
	var ew = eval(value.ew);
	var len = ew.length;
	if(ew.length>0){
		for ( var i = 0; i < len; i++) {
			var status = ew[i].ew_status;
			var syan = "";
			if(ew[i].ew_up_nco!=""){
				syan ="<li>"
					+ "<div class=\"info-list-name\">上月安排：</div>"
					+ "<div class=\"info-list-cont\">"+ ew[i].ew_up_nco+ "</div>"
					+ "</li>";
			}
			var pl1 = "<div class=\"kpi-main m-t18\">"
				+ "<h3 class=\"kpi-title icon-click\">"
				+ "<div class=\"row-left-icon\"><i>"+ (i + 1)+ "</i></div>"
				+ "<div class=\"info-list-cont\" id=\"desc\">"+ ew[i].ew_descr+ "</div>"
				+ "<div class=\"info-list-icon\" id=\"Desc\"></div>"
				+ "</h3>"
				+ "<div class=\"kpi-content row-info edit-row row-info-readonly\">"
				+ "<ul class=\"row-info-list\">"
				+ syan
				+ "<li>"
				+ "<div class=\"info-list-name\">实际完成：</div>"
				+ "<div class=\"info-list-cont\">"+ ew[i].ew_rea.replace(/\n/g,"<br>")+ "</div>"
				+ "</li> ";
			var pl2 = "";
			if(status=="CO"){
				pl2 = "<li>"+
					"<div class=\"info-list-name\">阶段汇总：</div>"
					+ "<div class=\"info-list-cont\">"+ ew[i].ew_sum.replace(/\n/g,"<br>")+ "</div>"
					+ "</li>"
					+ "<li>"
					+ "<div class=\"info-list-name\">完成情况：</div>"
					+ "<div class=\"info-list-cont\">"+"已完成"+"</div>"
					+ "</li>"
					+"</ul></div></div>";
			}else{
				pl2 = "<li>"+
					"<div class=\"info-list-name\">下月行动：</div>"
					+ "<div class=\"info-list-cont\">"+ ew[i].ew_nco.replace(/\n/g,"<br>")+ "</div>"
					+ "</li>"
					+ "<li>"
					+ "<div class=\"info-list-name\">完成情况：</div>"
					+ "<div class=\"info-list-cont\">"+"正在进行"+"</div>"
					+ "</li>"
					+"</ul></div></div>";
			}
			var pl = pl1 + pl2;
			$('#pList').append(pl);
		}
	}
	//解析ewn
	var ewn = eval(value.ewn);
	if(ewn.length>0){
		for(var i = 0 ; i < ewn.length ; i ++){
			var status = ewn[i].ewn_status;
			var syan = "";
			if(ewn[i].ewn_up_nco!=""){
				syan ="<li>"
					+ "<div class=\"info-list-name\">上月安排：</div>"
					+ "<div class=\"info-list-cont\">"+ ewn[i].ewn_up_nco+ "</div>"
					+ "</li>";
			}
			var pl1 = "<div class=\"kpi-main m-t18\">"
					+ "<h3 class=\"kpi-title icon-click\">"
					+ "<div class=\"row-left-icon\"><i>"+ (i+len+1)+ "</i></div>"
					+ "<div class=\"info-list-cont\" id=\"desc\">"+ ewn[i].ewn_descr+ "</div>"
					+ "<div class=\"info-list-icon\" id=\"Desc\"></div>"
					+ "</h3>"
					+ "<div class=\"kpi-content row-info edit-row row-info-readonly\">"
					+ "<ul class=\"row-info-list\">"
					+ syan
					+ "<li>"
					+ "<div class=\"info-list-name\">实际完成：</div>"
					+ "<div class=\"info-list-cont\">"+ ewn[i].ewn_rea.replace(/\n/g,"<br>")+ "</div>"
					+ "</li>";
			var pl2 = "";
			if(status=="CO"){
				pl2 = "<li>"
					+ "<div class=\"info-list-name\">阶段汇总：</div>"
					+ "<div class=\"info-list-cont\">"+ ewn[i].ewn_sum.replace(/\n/g,"<br>")+ "</div>"
					+ "</li>"
					+ "<li>"
					+ "<div class=\"info-list-name\">完成情况：</div>"
					+ "<div class=\"info-list-cont\">已完成</div>"
					+ "</li>"
					+"</ul></div></div>";
			}else{
				pl2 = "<li>"
					+ "<div class=\"info-list-name\">下月行动：</div>"
					+ "<div class=\"info-list-cont\">"+ ewn[i].ewn_nco.replace(/\n/g,"<br>")+ "</div>"
					+ "</li>"
					+ "<li>"
					+ "<div class=\"info-list-name\">完成情况：</div>"
					+ "<div class=\"info-list-cont\">正在进行</div>"
					+ "</li>"
					+"</ul></div></div>";
			}
			var pl = pl1 + pl2;
			$('#pList').append(pl);
		}
	}
	//需评分
	var ewg = eval(value.ewg);
	len = ewn.length+len;
	if(ewg.length>0){
		for ( var i = 0; i < ewg.length; i++) {
			var status = ewg[i].ewg_status;
			var syan = "";
			if(ewg[i].ewg_up_nco!=""){
				syan ="<li>"
					+ "<div class=\"info-list-name\">上月安排：</div>"
					+ "<div class=\"info-list-cont\">"+ ewg[i].ewg_up_nco+ "</div>"
					+ "</li>";
			}
			var pl1 = "<div class=\"kpi-main m-t18\">"
					+ "<h3 class=\"kpi-title icon-click\">"
					+ "<div class=\"row-left-icon\"><i>"+ (i +len+ 1)+ "</i></div>"
					+ "<div class=\"info-list-cont\" id=\"desc\">"+ ewg[i].ewg_descr+ "</div>"
					+ "<div class=\"info-list-icon\" id=\"Desc\"></div>"
					+ "</h3>"
					+ "<div class=\"kpi-content row-info edit-row row-info-readonly\">"
					+ "<ul class=\"row-info-list\">"
					+ syan
					+ "<li>"
					+ "<div class=\"info-list-name\">实际完成：</div>"
					+ "<div class=\"info-list-cont\">"+ ewg[i].ewg_rea.replace(/\n/g,"<br>")+ "</div>"
					+ "</li>";
			var pl2 = "";
			if(status=="CO"){
				pl2 = "<li>"
					+ "<div class=\"info-list-name\">阶段汇总：</div>"
					+ "<div class=\"info-list-cont\">"+ ewg[i].ewg_sum.replace(/\n/g,"<br>")+ "</div>"
					+ "</li>"
					+ "<li>"
					+ "<div class=\"info-list-name\">完成情况：</div>"
					+ "<div class=\"info-list-cont\">已完成</div>"
					+ "</li>";
			}else{
				pl2 = "<li>"
					+ "<div class=\"info-list-name\">下月行动：</div>"
					+ "<div class=\"info-list-cont\">"+ ewg[i].ewg_nco+ "</div>"
					+ "</li>"
					+ "<li>"
					+ "<div class=\"info-list-name\">完成情况：</div>"
					+ "<div class=\"info-list-cont\">正在进行</div>"
					+ "</li>";
			}
			if(value.iscyc == "1"){
				pl2 += "<li class=\"col-multi\">"
						+ "<div class=\"row-webkit-box col-multi-1\">"
							+ "<div class=\"info-list-name\">自评分：</div>"
							+ "<div class=\"info-list-cont\">"+ ewg[i].ewg_self_rating+ "<span class=\"fn-c-ccc\">分</span></div>" 
						+ "</div>"
						+"<div class=\"row-webkit-box col-multi-2\">"
	                    +"<div class=\"info-list-name\">我的评分：</div>"
	                    +"<div class=\"info-list-cont\">"+ewg[i].ewg_oth_rating+"</div>"
	                +"</div>"
					+ "</li></ul></div></div>";
			}else{
				pl2 += "</ul></div></div>";
			}
			var pl = pl1 + pl2;
			$('#pList').append(pl);
		}
	}
	if((ew.length+ewn.length+ewg.length)==0){
		$("#pList").parent().hide();
	}
	iscroll();
}
